import http from "../../../utils/http";
const common = require('../../../public.js')
// pages/mySelf/Accountbinding/Accountbinding.js
let appInfo = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        userInfo: {},//用户信息
        show:true
    },
    onLoad: function (options) {

    },
    onReady: function () {

    },
    onShow: async function () {
        var that = this
        var tempJson =  {
            userId:wx.getStorageSync('user').user.id,
            token:wx.getStorageSync('user').token
        }
        common.wxRequest('/user/getUserWxBindingInfo', 'post', tempJson, 'application/x-www-form-urlencoded', function (res) {
            if (res.status === 200) {
                if(res.data.length <= 0){
                    that.setData({
                        show:false
                    })
                    return
                }else{
                    that.setData({
                        userInfo:res.data[0]
                    })
                    // this.id  = res.data.data[0].unionid
                    that.setData({
                        id :res.data[0].unionid
                    })
                }
            }
          })
      
    },
    //解绑
    Unbound() {
        let _this = this
    wx.showModal({
        title: '解绑',
        content: '您确定要解绑吗',
        async  success (res) {
          if (res.confirm) {
            var tempJson={
                        userId:wx.getStorageSync('user').user.id,
                        token:wx.getStorageSync('user').token,
                        unionId:_this.data.id
                    }
            common.wxRequest('/user/cancleUserWxBinding', 'post', tempJson, 'application/x-www-form-urlencoded', function (res) {
               
           if(res.status == 200){
            _this.setData({
                show:false
            })
        }
          else if (res.cancel) {
            console.log('用户点击取消')       
          }
              })
      
          }
        }
      })
    },

})